000100******************************************************************
000200*PROGRAM : Build course ISAM                                     *
000300*AUTHOR  : Minh-Tuan Ta                                          *
000400******************************************************************
000500 IDENTIFICATION DIVISION.
000600 PROGRAM-ID. CRS-B.
000700 ENVIRONMENT DIVISION.
000800     SELECT INFILE       ASSIGN TO "COURSES.TXT"
000900                         ORGANIZATION IS LINE SEQUENTIAL.
001000
001100     SELECT SRTWRK       ASSIGN TO "SRTFILE.WRK".
001200
001300     SELECT OUTFILE      ASSIGN TO "CRSMST.DAT"
001400                         ORGANIZATION  IS INDEXED
001500                         ACCESS        IS SEQUENTIAL
001600                         RECORD KEY    IS OUT-COURSE-ID
001700                         FILE STATUS   IS WS-STAT.
001800
001900 DATA DIVISION.
002000 FILE SECTION.
002100 FD  INFILE.
002200 01  IN-REC.
002300     03  IN-COURSE-ID  PIC X(8).
002400     03  IN-COURSE-NAME  PIC X(34).
002500     03  IN-CREDIT-HR    PIC 99.
002600
002700 SD  SRTWRK.
002800 01  SRT-REC.
002900     03  SRT-CRS-ID    PIC X(8).
003000     03  SRT-CRS-NAME    PIC X(34).
003100     03  SRT-CREDIT-HR   PIC 99.
003200
003300 FD  OUTFILE.
003400 01  OUT-REC.
003500     03  OUT-COURSE-ID PIC X(8).
003600     03  OUT-COURSE-NAME PIC X(34).
003700     03  OUT-CREDIT-HR   PIC 99.
003800     03  OUT-ACTIVE      PIC X.
003900
004000 WORKING-STORAGE SECTION.
004100 01  WS-STAT         PIC XX.
004200 01  WS-EOF          PIC X VALUE 'N'.
004300 SCREEN SECTION.
004400 01  BUILDING-SCRN.
004500     03  BLANK SCREEN.
004600     03  LINE 12 COL 32 VALUE "BUILDING COURSE FILE".
004700 01  ERROR-SCRN.
004800     03  BLANK SCREEN.
004900     03  LINE 12 COL 32 VALUE "ERROR BUILDING FILE".
005000     03  LINE 14 COL 32 VALUE "FILE STATUS:".
005100     03          COL 46 PIC XX FROM WS-STAT.
005200     03  LINE 15 COL 32 VALUE "RECORD KEY:".
005300     03          COL 46 PIC X(5) FROM SRT-CRS-ID.
005400     03  LINE 19 COL 32 VALUE "PROGRAM TERMINATED".
005500
005600
005700 PROCEDURE DIVISION.
005800 100-MAIN.
005900     OPEN OUTPUT OUTFILE.
006000     DISPLAY BUILDING-SCRN
006100     SORT SRTWRK ON ASCENDING KEY SRT-CRS-ID
006200                 USING INFILE
006300                 OUTPUT PROCEDURE 200-CREATE-OUTPUT.
006400     CLOSE OUTFILE.
006500     EXIT PROGRAM.
006600
006700 200-CREATE-OUTPUT.
006800     RETURN SRTWRK AT END MOVE 'Y' TO WS-EOF.
006900     PERFORM 300-LOOP UNTIL WS-EOF = 'Y'.
007000
007100 300-LOOP.
007200     MOVE SRT-CRS-ID TO OUT-COURSE-ID
007300     MOVE SRT-CRS-NAME TO OUT-COURSE-NAME
007400     MOVE SRT-CREDIT-HR TO OUT-CREDIT-HR
007500     MOVE 'Y' TO OUT-ACTIVE
007600     WRITE OUT-REC
007700         INVALID KEY DISPLAY ERROR-SCRN
007800         STOP RUN
007900     END-WRITE
008000     RETURN SRTWRK AT END MOVE 'Y' TO WS-EOF.
